package com.zgm.ch06.aop.aspectJ.introduce._2_7;


import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;
import org.aspectj.lang.annotation.Pointcut;

import com.zgm.ch06.aop.aspectJ.introduce._2_7.interfaces.CallTracker;

@Aspect
public class CallTrackerAspect {

	@Pointcut("execution(* com.zgm.ch06.aop.services.*.*(..))")
	private void serviceCall() {}
	
	@DeclareParents(value = "com.zgm.ch06.aop.services.*",
					defaultImpl = DefaultCallTracker.class)
	public static CallTracker mixin;
	
	@AfterReturning(value = "serviceCall() && this(tracker)",
					argNames = "tracker")
	public void normalCall(CallTracker tracker) {
		System.out.println("成功！");
		
		tracker.markNormal();
	}
	
	@AfterThrowing(value = "serviceCall() && this(tracker)",
				   throwing = "t",
				   argNames = "tracker, t")
	public void failingCall(CallTracker tracker, Throwable t) {
		System.out.println("失败！");
		tracker.markFailing();
	}
}
